package middlewarex

import (
	"github.com/gin-gonic/gin"

	"zhonghui/console/warehouse/envx"
	"zhonghui/console/warehouse/helperx"
)

// InternalApi 判断内网中间件
func InternalApi() gin.HandlerFunc {
	return func(c *gin.Context) {
		ip := c.ClientIP()

		// 非生产环境放行
		if !envx.InProd() && !envx.InPre() {
			c.Next()
			return
		}

		// 判断内网IP
		if helperx.IsInternalIp(ip) {
			c.Next()
			return
		}

		c.String(200, "oks")
		c.Abort()
	}
}
